package com.srmt.document.model;

/**
 * 权限类型枚举
 * 
 * @author YourCompany
 * @since 1.0.0
 */
public enum PermissionType {
    
    /**
     * 只读权限
     */
    READ_ONLY("read", "只读"),
    
    /**
     * 评论权限
     */
    COMMENT("comment", "评论"),
    
    /**
     * 读写权限
     */
    READ_WRITE("write", "编辑"),
    
    /**
     * 完全控制权限
     */
    ADMIN("admin", "管理员"),
    
    /**
     * 所有者权限
     */
    OWNER("owner", "所有者");
    
    private final String code;
    private final String description;
    
    PermissionType(String code, String description) {
        this.code = code;
        this.description = description;
    }
    
    public String getCode() {
        return code;
    }
    
    public String getDescription() {
        return description;
    }
    
    /**
     * 根据code获取权限类型
     * 
     * @param code 权限代码
     * @return 权限类型
     */
    public static PermissionType fromCode(String code) {
        for (PermissionType type : values()) {
            if (type.code.equalsIgnoreCase(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("未知的权限类型代码: " + code);
    }
    
    /**
     * 检查是否有读权限
     */
    public boolean canRead() {
        return true; // 所有权限类型都可以读
    }
    
    /**
     * 检查是否有写权限
     */
    public boolean canWrite() {
        return this == READ_WRITE || this == ADMIN || this == OWNER;
    }
    
    /**
     * 检查是否有评论权限
     */
    public boolean canComment() {
        return this != READ_ONLY;
    }
    
    /**
     * 检查是否有管理权限
     */
    public boolean canManage() {
        return this == ADMIN || this == OWNER;
    }
    
    /**
     * 检查是否是所有者
     */
    public boolean isOwner() {
        return this == OWNER;
    }
    
    @Override
    public String toString() {
        return description;
    }
}